<template>
  <a-card :bordered="false">
    <super-query :fieldList="tableObj.columns" @ok="handleSuperQuery"/>
    <v-table
      ref="table"
      :data="loadData"
      :columns="tableObj.columns"
    >
      <template v-slot:buttons>
        <a-button @click="$refs.appForm.init('','add')" icon="plus" type="primary" v-action="'sys:user:save'">新增应用</a-button>
      </template>
      <span slot="action" slot-scope="{ row,text }">
        <span v-action="'sys:user:update'">
          <a href="javascript:;" @click="edit(row)">编辑</a>
          <a-divider type="vertical" />
        </span>
      </span>
    </v-table>
    <app-form @ok='queryPage' ref='appForm'></app-form>
  </a-card>
</template>

<script>
import SuperQuery from '@comp/SuperQuery/SuperQuery'
import { tableObj } from './template'
import { TableMixin } from '@/mixins/TableMixin'
import { fetchList } from '@/api/sys/app'
import appForm from './appForm'
export default {
  name: 'index',
  components: {
    SuperQuery,
    appForm
  },
  mixins: [TableMixin],
  data() {
    return {
      tableObj,
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    edit (record) {
      this.$refs.appForm.init(record.id, 'edit')
    },
    handleSuperQuery (params) {
      console.log(params,'params')
      if(params){
        this.queryParam.queryType = params.queryType
        this.queryParam.queryItems = encodeURI(JSON.stringify(params.queryItems))
      }else{
        this.queryParam.queryType = ''
        this.queryParam.queryItems = ''
      }
      this.queryPage()
    },
  }
}
</script>

<style scoped>

</style>